﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - ProgramSchemaModify" 
*/ 

component 
	displayname="public.service.db.senate.sequence.ProgramSchemaModify" 
	output=false 
	accessors=true 
	{
	
	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getID() output=false {
		
		var nextID = year(now()) & numberFormat(1, "0_____");
		
		var sql = "	SELECT
						sm.sign_id
					FROM
						t_schema_modify sm
					WHERE
						sm.sign_id LIKE :condition 
					ORDER BY
						sm.sign_id DESC";
		
		var queryObj = new Query(datasource = application.dnsMaster,maxRows=1);
		
		queryObj.addParam(name="condition", value=year(now()) & "______", cfsqltype="cf_sql_char");
		
		var rs_check = queryObj.execute(sql=sql).getResult();
		
		/* 
			主键生成规则 
			
			4位年份 + 6位流水号
			
		*/
		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = year(now()) & numberFormat((right(rs_check.sign_id, 6) + 1), "0_____");
			
		}

		return nextID;
	}

}

</cfscript>